﻿using System.Reflection;
using System.Runtime.Versioning;

namespace DBUtility.Standard
{
    public class DBHelperFactory
    {
        /// <summary>
        /// 获取一个IDBHelper对象
        /// </summary>
        public static IDBHelper CreateInstance(string connectionString, string providerName)
        {
            IDBHelper _iDBHelper = null;

            if (!string.IsNullOrEmpty(providerName))
            {
                switch (providerName)
                {
                    case "Microsoft.Data.SqlClient":
                        _iDBHelper = new SqlServerHelper(connectionString);
                        break;
                    case "MySql.Data.MySqlClient":
                        _iDBHelper = new MySqlHelper(connectionString);
                        break;
                    case "System.Data.OracleClient":
                        _iDBHelper = new OracleHelper(connectionString);
                        break;
                    case "System.Data.OleDb":
                        _iDBHelper = new OleDbHelper(connectionString);
                        break;
                    case "System.Data.PostgreSQL":
                        _iDBHelper = new PostgreSqlHelper(connectionString);
                        break;
                    //========还可以写Access数据库的类似MySqlDBHelper和SqlDBHelper的访问类，等等===========
                    default:
                        _iDBHelper = new SqlServerHelper(connectionString);
                        break;
                }
            }
            return _iDBHelper;
        }
    }
}
